import { get } from './common'
import { VersionResp, Pagination, ProjectReq, ProjectResp, UsersReq, EventsReq, CommitsReq } from './index.d'


export const defaultPage: Pagination = {
  pagination: 'keyset',
  sort: 'asc',
  per_page: 100
}

/**
 * 获取版本信息
 * @returns 版本信息
 */
export function version() {
  return get<VersionResp>('/version')
}

/**
 * 查询项目信息
 * @returns 分页查询项目信息
 */
export function projects(req?: ProjectReq, page?: Pagination) {
  return get<ProjectResp[]>('/projects', { ...defaultPage, ...req, ...page, })
}

/**
 * 获取用户信息
 * @param req 用户信息实体
 * @returns
 */
export function users(req?: UsersReq) {
  return get(`/users`, req)
}


export function events(req?: EventsReq, page?: Pagination) {
  return get(`/events`, { ...defaultPage, ...req, ...page, })
}

export function userEvents(userId: string, req?: EventsReq, page?: Pagination) {
  return get(`/users/${userId}/events`, { ...defaultPage, ...req, ...page, })
}

/**
 * 获取项目所有提交
 * @param projectId 项目Id
 * @param req 参数
 * @param page 分页
 * @returns
 */
export function commits(projectId: number, req?: CommitsReq, page?: Pagination) {
  return get(`/projects/${projectId}/repository/commits`, { ...req, ...page })
}
/**
 * 查询某次commit
 * @param projectId 项目
 * @param commitId 提交id
 * @returns
 */
export function commitInfo(projectId: string, commitId: string) {
  return get(`/projects/${projectId}/repository/commits/${commitId}`)
}
